<template>
  <div>
    <basic-container>内容审核 / 作品 / 章节审核</basic-container>
    <avue-form
      ref="form"
      :option="option"
      v-model="form"
      @submit="submit"
      @error="error"
    >  
      <!-- 通过与拒绝按钮 -->
      <template slot-scope="scope" slot="tgbtn">
        <div>
          <el-button type="success" @click="refuse(1)">通过</el-button>
        </div>
      </template>
	  
      <template slot-scope="scope" slot="jjbtn">
        <div>
          <el-button type="warning" @click="refuse(2)">拒绝</el-button>
        </div>
      </template>
    </avue-form>
  </div>
</template>

<script type="text/javascript" src='https://avuejs.com/cdn/aliyun-oss-sdk.min.js'></script>
<script src="https://avuejs.com/cdn/CryptoJS.js"></script>
<script>
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { appBookChapterCheck as baseURL, uploadFile } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      form: {},
	  content_show:'',
      option: {
        column: [
          {
            label: "书籍名称",
            prop: "book_title",
            span: 13,
            type: "input",
            readonly:true, 
          },
          {
            label: "章节类型",
            prop: "content_type",
            type: "select",
            span: 13,
            dicData: [ 
              {
                label: "正文",
                value: 0,
              },
              {
                label: "人设",
                value: 1,
              },
            ],
            readonly:true, 
          },
          {
            type: "input",
            label: "章节标题",
            span: 18,
            prop: "title",
            placeholder: "章节标题",
            readonly:true, 
          },
          // {
          //   type: "ueditor",
          //   component: "avue-ueditor",
          //   label: "章节内容",
          //   readonly:true, 
          //   span: 18,
          //   options: {
          //     action: `${catUrl+uploadFile.uploadFile}`,
          //     // oss: "",
          //     props: {
          //       url:'source'
          //     },
          //     // ali: {},
          //     // qiniu: {},
          //   },
          //   prop: "content",
          //   // title: "日历",
          //   labelWidth: "150",
          //   params: {},
          // },
			{
			  type: "ueditor",
			  component: "avue-ueditor",
			  label: "查看",
			  readonly:true, 
			  span: 18,
			  options: {
			    action: `${catUrl+uploadFile.uploadFile}`,
			    // oss: "",
			    props: {
			      url:'source'
			    },
			    // ali: {},
			    // qiniu: {},
			  },
			  disabled:true,
			  prop: "content_show",
			  // title: "日历",
			  labelWidth: "150",
			  params: {},
			},
          {
            label: "通过按钮",
            prop: "tgbtn",
            span: 18,
            formslot: true,
            labelslot: true,
          },
          {
            type: "textarea",
            label: "拒绝理由",
            span: 18,
            prop: "refusal_reason",
            placeholder: "拒绝理由",
            disabled: false,
          },
          {
            label: "拒绝按钮",
            prop: "jjbtn",
            span: 18,
            formslot: true,
            labelslot: true,
          },
        ],
        labelPosition: "right",
        labelSuffix: "：",
        labelWidth: 150,
        menuBtn: false,
        submitBtn: false,
        submitText: "提交",
        emptyBtn: true,
        emptyText: "清空",
        menuPosition: "center",
        gutter: 0,
        tabs: false,
        detail: false,
      },
    };
  },
  async created() {},
  methods: {
    submit(form, done) {
      this.$message.success(JSON.stringify(form));
      done();
    },
    error(err) {
      this.$message.success("请查看控制台");
    },
    //拒绝
    refuse(type) {
      this.$confirm(type == 1 ? "确定审核通过?" : "确定拒绝?", "王牌特战小提示", {
        type: "warning",
      }).then(async () => {
        let userInfo = this.$store.state.user.userInfo;
        this.form.editor = userInfo.username;
        this.form.edit_time = new Date();
        if (type == 1) {
          //通过
          this.form.state = 2;
          this.form.refusal_reason == "";
        } else if (type == 2) {
          //拒绝
          this.form.state = 3;
          if (this.form.refusal_reason == "") {
            return this.$message.error("拒绝理由不能为空");
          }
        }
		delete(this.form.content_show)
		console.log(this.form)
        let data = await common(`${baseURL.updateBookChapterCheck}`, this.form, null, "POST");
        if (data == null) {
          
          // this.$confirm("前去审核书籍?", "王牌特战小提示", {
          //   type: "warning",
          // }).then(async () => {
            
          // });
          return;
        }
        this.$router.go(-1);
      });
    },
  },
  async mounted() {
    //查询书籍章节详情-连带书籍详情  根据章节id
    let { data } = await common(
      baseURL.getInfoById + "/" + this.$route.query.content_id,
      null,
      null,
      "GET"
    );
    data.content_show = data.content.replace(/\\n/g, "<br />")
    console.log(data);
    this.form = data
    return
		let content_show = {}
		let content_detail = ''
		content_show = eval('(' + data.content + ')')
		console.log(content_show.list)
		for (let x in content_show.list) {
			let d = content_show.list[x].text;
			d = '<p>' + d + '</p>'
			content_detail = content_detail + d
		}
		let key = "content_show";
		let value = content_detail
		data[key] = value;
		console.log(content_detail)
		console.log(data)
    this.form = data;
    // let regEx_img = "http://res.xsdoudou.com/doudoumanager\\s*=\\s*(.*?)[^>]*?>";
    // this.form.chapter_content="<p><img src='http://res.xsdoudou.com/doudoumanager/image.png'></p>"
  },
};
</script>

<style>
</style>